package com.jdk.learn.base;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by ricky
 * on 2018/3/12.
 */
public class DateUtils {

    /**
     * 日期遍历
     */
    public void foreachDate() {
        try {
            Calendar start = Calendar.getInstance();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

            start.setTime(sdf.parse("2017-06-30 23:59:59"));

            Long startTIme = start.getTimeInMillis();

            Calendar end = Calendar.getInstance();
            end.setTime(sdf.parse("2018-03-11 23:59:59"));
            Long endTime = end.getTimeInMillis();

            Long oneDay = 1000 * 60 * 60 * 24l;

            Long time = startTIme;
            while (time <= endTime) {
                Date d = new Date(time);
                System.out.println(sdf.format(d));
                time += oneDay;
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
}
